package com.rainng.coursesystem.controller;

import com.rainng.coursesystem.model.NotificationItem;
import com.rainng.coursesystem.manager.NotificationManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notifications")
public class NotificationController {
    @Autowired
    private NotificationManager notificationManager;

    @GetMapping
    public List<NotificationItem> getAllNotifications() {
        return notificationManager.getAllNotifications();
    }

    @PostMapping
    public ResponseEntity<NotificationItem> createNotification(@RequestBody NotificationItem notification) {
        NotificationItem createdNotification = notificationManager.createNotification(notification);
        return new ResponseEntity<>(createdNotification, HttpStatus.CREATED);
    }

    @DeleteMapping
    public ResponseEntity<String> deleteNotification(@RequestParam Long id) {
        try {
            notificationManager.deleteNotification(id);
            return ResponseEntity.ok("Notification deleted successfully!");
        } catch (Exception e) {
            return ResponseEntity.status(404).body("ID not found in notifications: " + e.getMessage());
        }
    }
}